package hn.sigit.view.workflow.transaction;

import hn.sigit.model.commons.IRight;
import hn.sigit.model.hnd.ladmshadow.Right;
import hn.sigit.model.ladm.administrative.LA_RightType;
import hn.sigit.model.ladm.external.ExtParty;
import hn.sigit.view.ShareValue;

public class ParcelRight extends ParcelRRR {
	private LA_RightType rrrType;
	
	public ParcelRight(long presentationId, ExtParty extParty) {
		super(presentationId, extParty);
		this.rrr = Right.newRight(0, presentationId, false, false);
	}
	public ParcelRight(long presentationId, ExtParty extParty, ShareValue share, IRight right) {
		super(presentationId, extParty, share);
		this.rrr = right;
		this.rrrType = (LA_RightType) ((IRight) rrr).getType();
	}
	
	@Override
	public LA_RightType getRrrType() {
		return rrrType;
	}
	public void setRrrType(LA_RightType rrrType) {
		if (this.rrrType != rrrType) {
			this.rrrType = rrrType;
			setModified(true);
		}
	}
	//this is to make it work on Mac OS X servers
	public void setRrrType(Object rrrType) {
		setRrrType((LA_RightType) rrrType);
	}
	
	@Override
	public String getTypeString() {
		if (rrrType == null) return "";
		
		return rrrType.name();
	}
	
	
	public void cancelChanges() {
		if (rrr == null) return;
		
		super.cancelChanges();
		this.rrrType = ((Right)rrr).getType();
	}
	
	protected void applyChanges() {
		if (rrr == null) return;
		
		super.applyChanges();
		((Right)rrr).setType((LA_RightType)rrrType);
	}
}
